using System;
using System.Collections.Generic;
using UnityEngine;

public class Room : MonoBehaviour
{
    //房间列
    public int column;
    //房间行
    public int line;
    //房间图标
    private SpriteRenderer spriteRenderer;
    //房间数据
    public RoomDataSO roomDataSO;
    //房间状态
    public RoomState roomState;

    public List<Vector2Int> linkTo = new();
    
    [Header("广播")]
    public ObjectEventSO loadRoomEvent;

    private void Awake()
    {
        spriteRenderer = GetComponentInChildren<SpriteRenderer>();
    }
    

    private void OnMouseDown()
    {
        //处理点击事件
        if (roomState == RoomState.Attainable)
            loadRoomEvent.RaisEvent(this, this);
    }

    /// <summary>
    /// 外部创建房间时调用配置房间
    /// </summary>
    /// <param name="column"></param>
    /// <param name="line"></param>
    /// <param name="roomDataSO"></param>
    public void SetupRoom(int column, int line, RoomDataSO roomDataSO)
    {
        this.column = column;
        this.line = line;
        this.roomDataSO = roomDataSO;
        
        spriteRenderer.sprite = roomDataSO.roomIcon;
        
        spriteRenderer.color = roomState switch
        {
            RoomState.Locked => Color.gray,
            RoomState.Visited => Color.black,
            RoomState.Attainable => Color.white,
            _ => Color.black
        };
    }
}
